package org.reliablesource.prism.gef.editor.commands;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.commands.Command;
import org.reliablesource.prism.core.IPrismAnnotation;
import org.reliablesource.prism.gef.editor.model.ScreenAdapter;
import org.reliablesource.prism.gef.editor.model.StickyNoteAdapter;
import org.reliablesource.prism.gef.editor.parts.ScreenEditPart;

/**
 * 
 * StickyNoteTextCommand.java<br> 
 * Created on: Jul 12, 2007<br>
 *
 * @author Dennis Park 
 * 		<a href="mailto:dennis.park@gmail.com">dennis.park@gmail.com</a>
 *
 *  @since 1.0
 */
public class StickyNoteTextCommand extends Command {

	private String newString, oldString;

	final private StickyNoteAdapter label;
	
	final private ScreenEditPart parent;

	public StickyNoteTextCommand(final StickyNoteAdapter l, final String s, final EditPart _parent) {
		label = l;
		if (s != null)
			newString = s;
		else
			newString = "Click here to edit."; //$NON-NLS-1$
		
		parent = (ScreenEditPart) _parent;
	}

	public void execute() {
		oldString = (String) label.getPropertyValue(IPrismAnnotation.TEXT);
		label.setPropertyValue(IPrismAnnotation.TEXT, newString);
		((ScreenAdapter)parent.getModel()).childPropertyChange(label, IPrismAnnotation.TEXT, newString);
	}

	public void undo() {
		label.setPropertyValue(IPrismAnnotation.TEXT, oldString);
		((ScreenAdapter)parent.getModel()).childPropertyChange(label, IPrismAnnotation.TEXT, oldString);
	}

}
